package com.ge.med.cchelper.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringHelper {
	private final static String regxpForPath = "(/([0-9a-zA-Z]+))+";

	private final static String regxpForVobPath= "/.+@@.+";
	
	private final static String regxpForVobPathNoversion= "(/vobs/.+)";
	
	public static String matchPath(String str) {
		Pattern pattern = Pattern.compile(regxpForPath);
		Matcher matcher = pattern.matcher(str);
		String realPath = "";
		while (matcher.find()) {
			realPath = matcher.group();
		}
		return realPath;
	}
	
	public static String matchVobPath(String str) {
		Pattern pattern = Pattern.compile(regxpForVobPath);
		Matcher matcher = pattern.matcher(str);
		String realPath = "";
		while (matcher.find()) {
			realPath = matcher.group();
		}
		return realPath;
	}
	
	public static String matchVobsPwd(String str) {
		Pattern pattern = Pattern.compile(regxpForVobPathNoversion);
		Matcher matcher = pattern.matcher(str);
		String contents = "";
		StringBuilder allCheckOutFiles= new StringBuilder("");
		while (matcher.find()) {
			String realPath = matcher.group();
			contents = contents+"\n   "+realPath;
			System.out.println("@@@@@@@@:"+realPath);
			if(!realPath.trim().equals(""))
			   allCheckOutFiles.append(realPath+"\r\n");
		}
		return allCheckOutFiles.toString();
	}
	
	public static void main(String[] str){
		String test= "cleartool: Error: Unable to determine view for \"/vobs/com_platform\": Input/output error." +
	"cleartool: Error: Unable to determine view for \"/vobs/iungo\": Input/output error."+
"/vobs/jrx/ekg/src/com/ge/med/fct/ekg/context/SnapShotAssistContext.java"+
"/vobs/jrx/ekg/src/com/ge/med/fct/ekg/action/actions/ApplySettingsAction.java"+
"/vobs/jrx/ekg/src/com/ge/med/fct/ekg/command/commands/UpdateRecommendationCommand.java"+
"/vobs/jrx/ekg/test/com/ge/med/fct/ekg/command/commands/MinimizeViewerCommandTest.java"+
"/vobs/jrx/ekg/test/com/ge/med/fct/ekg/command/commands/MaximizeViewerCommandTest.java"+
"cleartool: Error: Unable to determine view for \"/vobs/aw2\": Stale NFS file handle."+
"cleartool: Error: Unable to determine view for \"/vobs/infrastructure\": Input/output error.";
	String result = StringHelper.matchVobsPwd(test);
	
	//System.out.println("@@@@@@@@:"+result);
	}

}
